<template>
  <div>
    <el-row>
      <el-col :span="24">
        <el-form :inline="true" style="float:left">
          <slot name="search-box"></slot>
        </el-form>
        <el-form :inline="true" style="float:right">
          <el-form-item>
            <el-button-group>
              <div class="refresh-btn" @click="init">
                <i class="el-icon-refresh" style="font-size:25px;"></i>
              </div>
              <el-button
                size="small"
                icon="el-icon-arrow-left"
                @click="prev"
                :disabled="requestData.postData.page_num == 1"
              ></el-button>
              <el-button
                size="small"
                :disabled="requestData.postData.page_num > total/requestData.postData.page_size"
                @click="next"
              >
                <i class="el-icon-arrow-right el-icon--right"></i>
              </el-button>
            </el-button-group>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
    <el-container class="main-container">
      <slot name="table-box"></slot>
    </el-container>
    <el-row style="padding-top:10px;">
      <el-col :span="24">
        <el-pagination
          style="float:right"
          background
          layout="total,prev, pager, next,jumper"
          :total="total"
          :page-size="requestData.postData.page_size?requestData.postData.page_size:20"
          :current-page="requestData.postData.page_num"
          @current-change="handleCurrentChange"
        ></el-pagination>
      </el-col>
    </el-row>
  </div>
</template>
<script>
export default {
  name: "igftable",
  data() {
    return {
      total: 0
    };
  },
  props: {
    requestData: {
      type: Object,
      default: {}
    },
    headShow: {
      type: Boolean,
      default: true
    }
  },
  methods: {
    handleCurrentChange(val) {
      this.requestData.postData.page_num = val;
      this.init();
    },
    prev: function() {
      this.requestData.postData.page_num--;
      if (this.requestData.postData.page_num <= 0) {
        this.requestData.postData.page_num = 1;
      }
      this.init();
    },
    next: function() {
      this.requestData.postData.page_num++;
      this.init();
    },
    init() {
      this.$http
        .post(this.requestData.urlPath, this.requestData.postData)
        .then(res => {
          if (res.code === 200) {
            this.total = res.data.total;
            this.$emit("list", res.data.list);
          } else {
            this.$message.error("数据获取失败!");
          }
        })
        .catch(err => {
          this.$message.error(err.msg);
        });
    }
  },
  created() {
    this.init();
  }
};
</script>

<style scoped>
.refresh-btn {
  margin-right: 10px;
  float: left;
  cursor: pointer;
  color: #32cd32;
}
.refresh-btn:hover {
  color: #098109;
}
.refresh-btn:active {
  color: #32cd32;
}
</style>
